package o;

import android.app.DownloadManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Build.VERSION;
import android.os.Environment;
import com.huawei.appgallery.game.impl.GameResource;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ReqAccessTokenParm;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class cln {
    public static List<String> ˋ() {
        List<String> arrayList = new ArrayList();
        PackageManager packageManager = ContentManager.getInstant().getContext().getPackageManager();
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        for (ResolveInfo resolveInfo : packageManager.queryIntentActivities(intent, WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT)) {
            if (!ˊ(resolveInfo.activityInfo.packageName)) {
                arrayList.add(resolveInfo.activityInfo.packageName);
            }
        }
        return arrayList;
    }

    private static boolean ˊ(String str) {
        try {
            ApplicationInfo applicationInfo = ContentManager.getInstant().getContext().getPackageManager().getApplicationInfo(str, 0);
            if ((applicationInfo.flags & 1) == 0 && (applicationInfo.flags & DnsConfig.MAX_CACHE_ENTRIES) == 0) {
                return false;
            }
            return true;
        } catch (NameNotFoundException e) {
            return false;
        }
    }

    public static void ˊ() {
        ॱ().edit().putInt(ReqAccessTokenParm.STATE_LABEL, 1).commit();
    }

    public static int ˎ() {
        return ॱ().getInt(ReqAccessTokenParm.STATE_LABEL, -1);
    }

    public static SharedPreferences ॱ() {
        return ContentManager.getInstant().getContext().getSharedPreferences("GameResourcePreload", 0);
    }

    public static void ˏ() {
        if (ᐝ()) {
            ˏ(new File(ˋॱ(), "gameresource"));
        }
    }

    public static void ˏ(File file) {
        File[] listFiles = file.listFiles();
        if (listFiles != null) {
            for (File ˏ : listFiles) {
                ˏ(ˏ);
            }
        }
        ˋ(file);
    }

    public static void ʻ() {
        cle.ˎ.ˋ("GameResourcePreLoad", "Utils.doClear");
        ˏॱ();
        ˏ();
        clg.ˏ().ˎ();
    }

    private static void ˏॱ() {
        DownloadManager downloadManager = (DownloadManager) ContentManager.getInstant().getContext().getSystemService("download");
        for (GameResource ॱ : clg.ˏ().ˋ()) {
            cle.ˎ.ˋ("GameResourcePreLoad", "cancelDownloadingTask:" + ॱ.ॱ());
            downloadManager.remove(new long[]{ॱ.ʼ()});
        }
    }

    public static boolean ॱॱ() {
        try {
            if ((ContentManager.getInstant().getContext().getApplicationInfo().flags & 2) != 0) {
                return true;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    public static String ˋ(String str, String str2) {
        try {
            File file = new File(ˋॱ(), "gameresource" + File.separator + str);
            if (!file.exists()) {
                ॱ(file);
            }
            if (file.exists()) {
                return new File(file, str2).getAbsolutePath();
            }
            cle.ˎ.ˏ("GameResourcePreLoad", "Utils.getFinalPath failed");
            return "";
        } catch (Exception e) {
            cle.ˎ.ˏ("GameResourcePreLoad", "Utils.getFinalPath:" + e.getMessage());
            return "";
        }
    }

    public static long ʽ() {
        try {
            return ˋॱ().getFreeSpace();
        } catch (Throwable e) {
            cle.ˎ.ˋ("GameResourcePreLoad", "getFreeSize exception", e);
            return 0;
        }
    }

    public static boolean ᐝ() {
        if ("mounted".equals(Environment.getExternalStorageState())) {
            return true;
        }
        return false;
    }

    public static boolean ʼ() {
        return VERSION.SDK_INT >= 24;
    }

    public static void ॱ(boolean z) {
        if (ʼ() && !z) {
            cdx.ˊ(new 3());
        }
    }

    public static String ˎ(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("gameresource").append(File.separator).append("tmp").append(File.separator).append(str);
        return stringBuilder.toString();
    }

    public static String ˏ(String str) {
        return new File(ˋॱ(), ˎ(str)).getAbsolutePath();
    }

    public static File ˋॱ() {
        File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        if (!externalStoragePublicDirectory.exists()) {
            ॱ(externalStoragePublicDirectory);
        }
        return externalStoragePublicDirectory;
    }

    public static String ॱ(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("gameresource").append(File.separator).append(str);
        return new File(ˋॱ(), stringBuilder.toString()).getAbsolutePath();
    }

    public static void ˋ(File file) {
        if (!file.delete()) {
            cle.ˎ.ˏ("GameResourcePreLoad", "deleteFile failed");
        }
    }

    public static void ॱ(File file) {
        if (!file.mkdirs()) {
            cle.ˎ.ˏ("GameResourcePreLoad", "mkdirs failed");
        }
    }
}
